#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>

long App_Common_GetCurrentTime(void)
{
    struct timeval tv = {0};
    if(gettimeofday(&tv, NULL) == 0)
    {
        return tv.tv_sec * 1000 + tv.tv_usec / 1000;
    }
    else
    {
        return 0;
    }
}

char *App_Common_CharsToHex(char *chars, int chars_len)
{
    char *hex_str = (char*)malloc(chars_len * 2 + 1);
    if(hex_str == NULL)   return NULL;
    for(int i = 0; i < chars_len; i++)
    {
        sprintf(hex_str + i * 2, "%02x", chars[i]);
    }
    hex_str[chars_len * 2] = '\0';
    return hex_str;
}

char *App_Common_HexToChars(char *Hex, int Hex_len)
{
    char *chat_str = malloc(Hex_len / 2);
    if(chat_str == NULL)   return NULL;
    for(int i = 0; i < Hex_len; i+=2)
    {
        sscanf(Hex + i, "%02x", (unsigned int *)&chat_str[i / 2]);
    }
    return chat_str;
}
